In [1]:
%matplotlib inline
Problem: Write a program that prints the numbers from 1 to 100, one per line.
In [4]:
for i in range(1,101):
print(i)
Problem: Write a program that prints the numbers in the range [1 ... 1000], ending at 7.
In [6]:
for i in range(1,1001):
if i % 10 == 7:
print(i)
Problem: Write a program that prints all the letters of the Latin alphabet: a, b, c, ..., z.
In [9]:
for i in range(97,123):
print(chr(i))
Problem: Write a program that reads a number of integer numbers entered by the user and sums them.
In [12]:
num_of_loops = int(input())
sum = 0;
for i in range(1, num_of_loops + 1):
num = int(input())
sum += num
print(sum)
Problem: Write a program that reads n number of integers (n > 0) entered by the user, the greatest among them. First, the number of ns is entered, and then the n numbers themselves, one per line.
In [14]:
num_of_loops = int(input())
new_num = 0
max_num = 9223372036854775807 * (-1)
for i in range(1 , num_of_loops + 1):
new_num = int(input())
if new_num > max_num:
max_num = new_num
print(max_num)
Problem: Write a program that reads n number of integers (n > 0) entered by the user, few of them. First, the number of ns is entered, and then the n numbers themselves, one per line.
In [16]:
num_of_loops = int(input())
min_num = 9223372036854775807
new_num = 0
for i in range(1, num_of_loops + 1):
new_num = int(input())
if new_num < min_num:
min_num = new_num
print(min_num)
Problem: Write a program that reads 2 * ns of whole integers filed by the user and checks if the sum of the first n numbers (left sum) is equal to the sum of the second n numbers (right amount). In case of equality print "Yes" + the sum; otherwise "No" + difference. The difference is calculated as a positive number (inabsolute value).
In [18]:
import math
num_of_loops = int(input())
first_sum = 0
second_sum = 0
difference = 0
for i in range(1, num_of_loops * 2 + 1):
number = int(input())
if i <= num_of_loops:
first_sum += number
else:
second_sum += number
difference = math.fabs(first_sum - second_sum)
if difference == 0:
print(f"Yes, sum = {first_sum}")
else:
print(f"No, diff = {difference}")
Problem: Write a program that reads the numbers submitted by the user and checks the sum of the even positions is equal to the sum of the odd numbers. In the case of equality, the "Yes" + amount is printed; otherwise you can print the "No" + difference. The difference is calculated in absolute terms value.
In [19]:
import math
num_of_loops = int(input())
odd_sum = 0
even_sum = 0
difference = 0
for i in range(1,num_of_loops + 1):
num = int(input())
if i % 2 != 0:
odd_sum += num
else:
even_sum += num
difference = math.fabs(odd_sum - even_sum)
if difference == 0:
print(f"Yes, sum = {odd_sum}")
else:
print(f"No, diff = {difference}")
Problem: Write a program that reads a text (string) entered by the user and calculates and prints the amount of the values of the uppercase letters in the table below:
letter | a | e | i | o | u |
---|---|---|---|---|---|
value | 1 | 2 | 3 | 4 | 5 |
Problem: Write a program that reads n-number integer numbers entered by the user and checks if among there is a number that is equal to the sum of all others. If there is such an item, print "Yes ,Sum = + its value" otherwise the "No", "Diff = + the difference between the largest element and the sum of the rest" (in absolute terms).
In [22]:
import math
num_of_loops = int(input())
sum = 0
max_num = 0
new_num = 0
for i in range(1 , num_of_loops + 1):
new_num = int(input())
if new_num > max_num:
max_num = new_num
sum += new_num
if sum / 2 == max_num:
print(f"Yes, Sum = {max_num}")
else:
print(f"No, diff = {math.fabs((sum - max_num) - max_num)}")
Problem: Write a program that reads n-number numbers entered by the user and calculates the amount, minimum and the maximum of the even and odd numbers (1 count). When there is no minimum / maximum item, print "No".
In [24]:
import math
num_of_loops = int(input())
odd_sum = 0
odd_min = math.inf
odd_max = math.inf * (-1)
even_sum = 0
even_min = math.inf
even_max = math.inf * (-1)
new_num = 0
for i in range(1, num_of_loops + 1):
new_num = float(input())
if i % 2 != 0:
odd_sum += new_num
if new_num < odd_min:
odd_min = new_num
if new_num > odd_max:
odd_max = new_num
else:
even_sum += new_num
if new_num < even_min:
even_min = new_num
if new_num > even_max:
even_max = new_num
if odd_sum == 0:
print(f"OddSum = 0")
else:
print(f"OddSum = {odd_sum}")
if odd_min != math.inf:
print(f"OddMin = {odd_min},")
else:
print(f"OddMin = No,")
if odd_max != (math.inf * (-1)):
print(f"OddMax = {odd_max},")
else:
print("OddMax = No,")
if even_sum == 0:
print(f"EvenSum = 0,")
else:
print(f"EvenSum = {even_sum},")
if even_min != math.inf:
print(f"EvenMin = {even_min},")
else:
print("EvenMin = No,")
if even_max != (math.inf * (-1)):
print(f"EvenMax = {even_max}")
else:
print(f"EvenMax = No")
Problem: Given are 2 * n-numbered numbers. The first and the second form a pair, the third and the fourth also, etc. Each pair has value - the sum of its numbers. Write a program that checks if everyone pairs have the same value or print the maximum difference between two consecutive pairs. If all pairs have the same value,print: "Yes, value = {Value} + value". Otherwise print "No, maxdiff = {Difference} " + maximum difference.
In [26]:
import math
num_of_loops = int(input())
num_1 = 0
num_2 = 0
first_pair = 0
second_pair = 0
max_num_of_equal_pairs = 0
max_diff = 0
difference = 0
for i in range(1, num_of_loops + 1):
num_1 = int(input())
num_2 = int(input())
if i % 2 != 0:
first_pair = num_1 + num_2
else:
second_pair = num_1 + num_2
if first_pair == second_pair:
max_num_of_equal_pairs += 1
difference = math.fabs(first_pair - second_pair)
if difference > max_diff and i > 1:
max_diff = difference
if (max_num_of_equal_pairs + 1) == num_of_loops:
print(f"Yes, value = {first_pair}")
else:
print(f"No, maxdiff = {max_diff}")